/*
 * Copyright (C), Hisilicon Technologies Co., Ltd. 2017-2019. All rights reserved.
 * Description   : drivers for user osal lib.
 * Author        :
 * Create        : 2017-10-20
 */

#include "user_osal_lib.h"

/* *********************** Internal Structure Definition ********************* */
#ifndef __HuaweiLite__
void hex2str(char buf[MUL_VAL_2], hi_u8 val)
{
    hi_u8 high, low;

    high = (val >> SHIFT_4BITS) & MAX_LOW_4BITS;
    low =  val & MAX_LOW_4BITS;

    if (high <= 9) {
        /* 0~9. */
        buf[WORD_IDX_0] = high + '0';
    } else {
        /* A~F. */
        buf[WORD_IDX_0] = (high - 0x0A) + 'A';
    }

    if (low <= 9) {
        /* 0~9. */
        buf[WORD_IDX_1] = low + '0';
    } else {
        /* A~F. */
        buf[WORD_IDX_1] = (low - 0x0A) + 'A';
    }

}


/* Implementation that should never be optimized out by the compiler. */
hi_void crypto_zeroize(hi_void *buf, hi_u32 len)
{
    volatile unsigned char *p = (unsigned char *)buf;

    if (buf == HI_NULL) {
        return;
    }

    while (len--) {
        *p++ = 0;
    }
}
#endif

hi_void print_string(const hi_s8 *name, hi_u8 *string, hi_u32 size)
{
#ifdef HI_CIPHER_TEST_SUPPORT
    hi_u32 i;
    hi_s8 buf[WORD_WIDTH] = {0};

    if (name != HI_NULL) {
        HI_PRINT("[%s-%p]:\n", name, string);
    }
    for (i = 0; i < size; i++) {
        hex2str(buf, string[i]);
        HI_PRINT("%c%c ", buf[0], buf[1]);
        if (((i + 1) % 16) == 0)
        { HI_PRINT("\n"); }
    }
    if ((i % 16) != 0) {
        HI_PRINT("\n");
    }
#endif
}
